package com.anjho.pojo;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;

@Entity
@Table(name = "city")
@NamedQueries(value = {
		@NamedQuery(name = "City.getCityList", query = "SELECT c FROM City c"),
		@NamedQuery(name = "City.getCityByCicode", query = "SELECT c FROM City c WHERE c.cicode = :cicode"),
		@NamedQuery(name = "City.getCityByZip", query = "SELECT c FROM City c WHERE c.zip = :zip")
})
public class City implements Serializable {

	private static final long serialVersionUID = -599386346260224871L;
	
	public City() {
		this.setCicode(0);
		this.setEstate(new Estate());
		this.setName("");
		this.setZip("");
	}
	
	@Id
	@Column(name="cicode")
	@OneToMany(mappedBy="city")
	private int cicode;
	
	@ManyToOne
	@JoinColumn(name="escode", nullable=false)
	private Estate estate;
	
	@Column(name="name", nullable=false, length=72)
	private String name;
	
	@Column(name="zip", nullable=false, length=8)
	private String zip;

	public int getCicode() {
		return cicode;
	}

	public void setCicode(int cicode) {
		this.cicode = cicode;
	}

	public Estate getEstate() {
		return estate;
	}

	public void setEstate(Estate estate) {
		this.estate = estate;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getZip() {
		return zip;
	}

	public void setZip(String zip) {
		this.zip = zip;
	}
	
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + cicode;
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		City other = (City) obj;
		if (cicode != other.cicode)
			return false;
		return true;
	}
}
